package zheezes.protocol.impl.gd;

import java.util.Calendar;

import zheezes.protocol.impl.gd.converter.DateConverter;
import zheezes.util.ByteUtil;


public class Ctrl13Frame extends GdFrame {
	private byte resend;
	private short start;
	private byte amount;
	private Calendar cal = Calendar.getInstance();
	private byte days;

	public Ctrl13Frame() {
	}
	
	public int sizeOfData() {
		return 8;
	}
	
	public int getData(byte[] buf, int offset) {
		int idx = offset;
		buf[idx++] = resend;
		ByteUtil.stoc(buf, idx, start);
		idx += 2;
		buf[idx++] = amount;
		System.arraycopy(DateConverter.vtob(cal), 0, buf, idx, 3);
		idx += 3;
		buf[idx++] = days;
		return idx - offset;
	}

	@Override
	public int setData(byte[] buf, int offset, int max) {
		int idx = offset;
		resend = buf[idx++];
		start = ByteUtil.ctos(buf, idx);
		idx += 2;
		amount = buf[idx++];
		byte[] tmp = new byte[3];
		System.arraycopy(buf, idx, tmp, 0, 3);
		cal.setTime(DateConverter.btov(tmp).getTime());
		idx += 3;
		days = buf[idx++];

		return idx - offset;
	}

	public byte getResend() {
		return resend;
	}

	public void setResend(byte resend) {
		this.resend = resend;
	}

	public short getStart() {
		return start;
	}

	public void setStart(short start) {
		this.start = start;
	}

	public byte getAmount() {
		return amount;
	}

	public void setAmount(byte amount) {
		this.amount = amount;
	}

	public Calendar getCal() {
		return cal;
	}

	public void setCal(Calendar cal) {
		this.cal = cal;
	}

	public byte getDays() {
		return days;
	}

	public void setDays(byte days) {
		this.days = days;
	}
}
